package com.group2.operations.mapper;

import com.group2.operations.model.Contract;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;


import java.util.Date;
import java.util.List;

@Repository
@Mapper
public interface ContractMapper {
    /**
     * 列举某个用户的所有合同
     * @param uid 用户ID
     * @return
     */
    @Select("select * from contract where uid=#{uid}")
    List<Contract> queryContractByUid(int uid);

    /**
     * 根据合同ID查找合同文件url
     * @param id 合同ID
     * @return
     */
    @Select("select url from contract where id=#{id}")
    String queryContractNameById(int id);

    /**
     * 将合同的签订标志位改为1
     * @param cid 合同ID
     */
    @Update("update contract set signed=1 where id=#{cid}")
    void signContract(int cid);

    /**
     * 更新合同的签订时间
     * @param cid 合同ID
     * @param time 时间
     */
    @Update("update contract set time=#{time} where id=#{cid}")
    void updateTime(@Param("cid") int cid, @Param("time") Date time);
}
